// 饼图的属性设置
export let pieChartConfiguration = {
    color: [
        "#1890FF",
        "#91CB74",
        "#FAC858",
        "#EE6666",
        "#73C0DE",
        "#3CA272",
        "#FC8452",
        "#9A60B4",
        "#ea7ccc"
    ],
    // 调整饼图出现后的内边距
    padding: [5, 5, 5, 5],
    extra: {
        pie: {
            activeOpacity: 0.5,
            activeRadius: 10,
            offsetAngle: 0,
            labelWidth: 15,
            border: true,
            borderWidth: 3,
            borderColor: "#FFFFFF",
            linearType: "custom"
        }
    }
}

export let histogramConfiguration = {
    color: [
        "#FAC858",
        "#73C0DE",
        "#FAC858",
        "#EE6666",
        "#73C0DE",
        "#3CA272",
        "#FC8452",
        "#9A60B4",
        "#ea7ccc"
    ],
    padding: [15, 15, 0, 5],
    legend: {},
    xAxis: {
        disableGrid: true
    },
    yAxis: {
        data: [
            {
                min: 0
            }
        ]
    },
    extra: {
        column: {
            type: "group",
            width: 30,
            activeBgColor: "#000000",
            activeBgOpacity: 0.08,
            linearType: "custom",
            seriesGap: 5,
            linearOpacity: 0.5,
            barBorderCircle: true,
            customColor: ["#FA7D8D", "#EB88E2"]
        }
    }
}

/**
 * @param result 识别的结果
 * @return {any} 饼状图所需要的数据格式
 */
export function pieChartData(result) {
    return JSON.parse(
        JSON.stringify({
            series: [
                {
                    data: [
                        // keyword是物体或动物的名称；score是“符合识别结果的几率”，越大就证明越贴近真实结果
                        // toFixed(2)能保留到小数点后两位，但会转为字符串，所以要用Number()将字符串转回数字类型
                        {
                            name: result[0].keyword,
                            value: Number(parseFloat(result[0].score * 100).toFixed(2))
                        },
                        {
                            name: result[1].keyword,
                            value: Number(parseFloat(result[1].score * 100).toFixed(2))
                        },
                        {
                            name: result[2].keyword,
                            value: Number(parseFloat(result[2].score * 100).toFixed(2))
                        },
                        {
                            name: result[3].keyword,
                            value: Number(parseFloat(result[3].score * 100).toFixed(2))
                        },
                        {
                            name: result[4].keyword,
                            value: Number(parseFloat(result[4].score * 100).toFixed(2))
                        }
                    ]
                }
            ]
        })
    );
}

/**
 * @param result 识别的结果
 * @return {any} 柱状图所需要的数据格式
 */
export function histogramChartData(result) {
    return JSON.parse(
        JSON.stringify({
            // 名称
            categories: [
                result[0].keyword,
                result[1].keyword,
                result[2].keyword,
                result[3].keyword,
                result[4].keyword
            ],
            // 具体数据
            series: [
                {
                    name: result[0].keyword,
                    data: [
                        Number(parseFloat(result[0].score * 100).toFixed(2)),
                        Number(parseFloat(result[1].score * 100).toFixed(2)),
                        Number(parseFloat(result[2].score * 100).toFixed(2)),
                        Number(parseFloat(result[3].score * 100).toFixed(2)),
                        Number(parseFloat(result[4].score * 100).toFixed(2))
                    ]
                }
            ]
        })
    );
}